load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

mongo_cc_library(
    name = "bson_collection_catalog_entry",
    srcs = [
        "bson_collection_catalog_entry.cpp",
    ],
    hdrs = [
        "bson_collection_catalog_entry.h",
    ],
    deps = [
        "//src/mongo/db:common",
        "//src/mongo/db/catalog:collection_options",
    ],
)

mongo_cc_library(
    name = "recovery_unit_base",
    srcs = [
        "recovery_unit.cpp",
        "recovery_unit.h",
        "recovery_unit_noop.cpp",
        "recovery_unit_noop.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:server_base",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util:fail_point",
    ],
)

mongo_cc_library(
    name = "record_store_base",
    srcs = [
        "collection_truncate_markers.cpp",
        "record_store.cpp",
        "record_store_base.cpp",
    ],
    hdrs = [
        "collection_truncate_markers.h",
        "damage_vector.h",
        "record_store.h",
        "record_store_base.h",
    ],
    deps = [
        ":storage_options",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:service_context",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "damage_vector",
    srcs = [],
    hdrs = [
        "damage_vector.h",
    ],
)

mongo_cc_library(
    name = "remove_saver",
    srcs = [
        "remove_saver.cpp",
    ],
    hdrs = [
        "remove_saver.h",
    ],
    deps = [
        ":encryption_hooks",
        ":storage_options",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:server_base",
    ],
)

mongo_cc_library(
    name = "journal_flusher",
    srcs = [
        "//src/mongo/db/storage/control:journal_flusher.cpp",
    ],
    hdrs = [
        "//src/mongo/db/storage/control:journal_flusher.h",
    ],
    deps = [
        ":storage_options",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/admission:execution_admission_context",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util:background_job",
        "//src/mongo/util:fail_point",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util/concurrency:spin_lock",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "encryption_hooks",
    srcs = [
        "encryption_hooks.cpp",
    ],
    hdrs = [
        "data_protector.h",
        "encryption_hooks.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:service_context",
    ],
)

mongo_cc_library(
    name = "backup_cursor_hooks",
    srcs = [
        "backup_cursor_hooks.cpp",
    ],
    hdrs = [
        "backup_cursor_hooks.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:service_context",
    ],
)

idl_generator(
    name = "storage_parameters_gen",
    src = "storage_parameters.idl",
)

mongo_cc_library(
    name = "capped_snapshots",
    srcs = [
        "capped_snapshots.cpp",
    ],
    hdrs = [
        "capped_snapshots.h",
    ],
    deps = [
        ":recovery_unit_base",  # TODO(SERVER-93876): Remove.
        "//src/mongo:base",
        "//src/mongo/db/concurrency:lock_manager",
    ],
)

idl_generator(
    name = "flow_control_parameters_gen",
    src = "flow_control_parameters.idl",
)

mongo_cc_library(
    name = "flow_control_parameters",
    srcs = [
        ":flow_control_parameters_gen",
    ],
    deps = [
        "//src/mongo/db:server_base",
    ],
)

mongo_cc_library(
    name = "flow_control",
    srcs = [
        "flow_control.cpp",
    ],
    hdrs = [
        "flow_control.h",
    ],
    deps = [
        ":flow_control_parameters",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/commands:server_status_core",
        "//src/mongo/db/concurrency:flow_control_ticketholder",
        "//src/mongo/util:background_job",
        "//src/mongo/util:fail_point",
    ],
)

mongo_cc_library(
    name = "storage_file_util",
    srcs = [
        "storage_file_util.cpp",
    ],
    hdrs = [
        "storage_file_util.h",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_library(
    name = "storage_repair_observer",
    srcs = [
        "storage_repair_observer.cpp",
    ],
    hdrs = [
        "storage_repair_observer.h",
    ],
    deps = [
        ":storage_file_util",
        "//src/mongo:base",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:service_context",
        "//src/mongo/db/repl:replica_set_messages",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/repl:storage_interface",
        "//src/mongo/db/storage:journal_flusher",
    ],
)

mongo_cc_library(
    name = "duplicate_key_error_info",
    srcs = [
        "duplicate_key_error_info.cpp",
    ],
    hdrs = [
        "duplicate_key_error_info.h",
    ],
    header_deps = [
        "//src/mongo/db/concurrency:flow_control_ticketholder",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_library(
    name = "execution_context",
    srcs = [
        "execution_context.cpp",
    ],
    hdrs = [
        "execution_context.h",
        "//src/mongo/util:auto_clear_ptr.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db/storage/key_string",
    ],
)

mongo_cc_library(
    name = "index_entry_comparison",
    srcs = [
        "index_entry_comparison.cpp",
        "//src/mongo/db/catalog:index_catalog.h",
        "//src/mongo/db/catalog:index_catalog_entry.h",
        "//src/mongo/db/index:index_descriptor.h",
        "//src/mongo/db/index:index_descriptor_fwd.h",
    ],
    hdrs = [
        "index_entry_comparison.h",
    ],
    deps = [
        ":duplicate_key_error_info",
        "//src/mongo/db:server_base",
        "//src/mongo/db/storage/key_string",
    ],
)

mongo_cc_library(
    name = "storage_engine_metadata",
    srcs = [
        "storage_engine_metadata.cpp",
    ],
    hdrs = [
        "storage_engine_metadata.h",
        "//src/mongo/base:data_type_validated.h",
        "//src/mongo/rpc:object_check.h",
    ],
    deps = [
        "//src/mongo/bson:bson_validate",
        "//src/mongo/db:server_base",
        "//src/mongo/db/query/bson:dotted_path_support",
    ],
)

mongo_cc_library(
    name = "storage_engine_lock_file",
    srcs = [
        "storage_engine_lock_file.cpp",
    ] + select({
        "@platforms//os:windows": ["storage_engine_lock_file_windows.cpp"],
        "//conditions:default": ["storage_engine_lock_file_posix.cpp"],
    }),
    hdrs = [
        "storage_engine_lock_file.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:service_context",
    ],
)

mongo_cc_library(
    name = "storage_options",
    srcs = [
        "storage_options.cpp",
        ":storage_parameters_gen",
    ],
    hdrs = [
        "storage_engine_interface.h",
        "storage_options.h",
    ],
    deps = [
        "//src/mongo/db:server_base",
    ],
)

mongo_cc_library(
    name = "durable_catalog",
    srcs = [
        "durable_catalog.cpp",
        "//src/mongo/db/catalog:import_options.h",
        "//src/mongo/db/storage/kv:kv_engine.h",
    ],
    hdrs = [
        "durable_catalog.h",
    ],
    deps = [
        ":bson_collection_catalog_entry",
        ":record_store_base",
        ":storage_options",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:server_base",
        "//src/mongo/db/concurrency:lock_manager",
        "//src/mongo/db/storage:feature_document_util",
        "//src/mongo/db/storage:ident",
    ],
)

mongo_cc_library(
    name = "storage_init_d",
    srcs = [
        "storage_init.cpp",
    ],
    deps = [
        ":backup_cursor_hooks",  # TODO(SERVER-93876): Remove.
        ":storage_options",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/commands:server_status_core",
    ],
)

mongo_cc_library(
    name = "disk_space_util",
    srcs = [
        "disk_space_util.cpp",
        "disk_space_util.h",
    ],
    deps = [
        ":storage_options",  # TODO(SERVER-93876): Remove.
        "//src/mongo:base",
        "//src/mongo/util:fail_point",
    ],
)

mongo_cc_library(
    name = "disk_space_monitor",
    srcs = [
        "disk_space_monitor.cpp",
    ],
    hdrs = [
        "disk_space_monitor.h",
    ],
    deps = [
        ":disk_space_util",
        ":storage_options",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:server_base",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:service_context",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/commands:server_status_core",
    ],
)

mongo_cc_library(
    name = "checkpointer",
    srcs = [
        "checkpointer.cpp",
    ],
    hdrs = [
        "checkpointer.h",
    ],
    deps = [
        ":storage_options",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util:background_job",
        "//src/mongo/util:fail_point",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util/concurrency:spin_lock",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "storage_control",
    srcs = [
        "durable_history_pin.cpp",
        "//src/mongo/db/storage/control:storage_control.cpp",
    ],
    hdrs = [
        "durable_history_pin.h",
        "//src/mongo/db/storage/control:storage_control.h",
    ],
    deps = [
        ":checkpointer",
        ":journal_flusher",
        ":storage_options",  # TODO(SERVER-93876): Remove.
        "//src/mongo:base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/commands:test_commands_enabled",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "write_unit_of_work",
    srcs = [
        "write_unit_of_work.cpp",
    ],
    hdrs = [
        "write_unit_of_work.h",
    ],
    header_deps = [
        "//src/mongo/db/commands:server_status_core",
        "//src/mongo/db/op_observer:op_observer",
    ],
    deps = [
        "recovery_unit_base",
        "storage_options",
        "//src/mongo:base",
        "//src/mongo/db/views",
    ],
)

mongo_cc_library(
    name = "backup_block",
    srcs = [
        "backup_block.cpp",
    ],
    hdrs = [
        "backup_block.h",
    ],
    deps = [
        ":storage_options",
        "//src/mongo/db:server_base",
        "//src/mongo/db:shard_role_api",
    ],
)

mongo_cc_library(
    name = "oplog_truncation",
    srcs = [
        "oplog_cap_maintainer_thread.cpp",
        "oplog_truncation.cpp",
    ],
    hdrs = [
        "oplog_cap_maintainer_thread.h",
        "oplog_truncation.h",
    ],
    deps = [
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db:shard_role",
        "//src/mongo/db/catalog:collection_catalog",
        "//src/mongo/db/catalog:local_oplog_info",
        "//src/mongo/db/commands:server_status_core",
        "//src/mongo/db/concurrency:lock_manager",
        "//src/mongo/util:background_job",
    ],
)

mongo_cc_library(
    name = "storage_engine_common",
    srcs = [
        "storage_engine_change_context.cpp",
        "storage_engine_init.cpp",
    ],
    hdrs = [
        "storage_engine_change_context.h",
        "storage_engine_init.h",
    ],
    deps = [
        ":storage_control",
        ":storage_engine_lock_file",
        ":storage_engine_metadata",
        ":storage_options",
        ":storage_repair_observer",
        "//src/mongo/db:service_context",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/exec:scoped_timer",
        "//src/mongo/util/concurrency:spin_lock",
    ],
)

mongo_cc_library(
    name = "storage_util",
    srcs = [
        "storage_util.cpp",
    ],
    hdrs = [
        "storage_util.h",
    ],
    deps = [
        ":durable_catalog",
        ":storage_options",
        "//src/mongo/db/catalog:collection_catalog",
        "//src/mongo/db/storage/kv:kv_drop_pending_ident_reaper",
    ],
)

mongo_cc_library(
    name = "storage_engine_impl",
    srcs = [
        "deferred_drop_record_store.cpp",
        "storage_engine_impl.cpp",
    ],
    hdrs = [
        "deferred_drop_record_store.h",
        "journal_listener.h",
        "storage_engine_impl.h",
    ],
    deps = [
        ":backup_block",
        ":durable_catalog",
        ":storage_control",
        ":storage_options",
        ":storage_repair_observer",
        ":storage_util",
        "//src/mongo/db:audit",
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db:shard_role",
        "//src/mongo/db:vector_clock",
        "//src/mongo/db/catalog:catalog_control",
        "//src/mongo/db/catalog:catalog_helpers",
        "//src/mongo/db/catalog:index_catalog",
        "//src/mongo/db/index_builds:resumable_index_builds_idl",
        "//src/mongo/db/index_builds:two_phase_index_build_knobs_idl",
        "//src/mongo/db/storage/kv:kv_drop_pending_ident_reaper",
    ],
)

mongo_cc_library(
    name = "feature_document_util",
    srcs = [
        "feature_document_util.cpp",
    ],
    hdrs = [
        "feature_document_util.h",
        "//src/mongo/bson:bsonelement.h",
        "//src/mongo/bson:bsonobj.h",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_library(
    name = "ident",
    srcs = [
        "ident.cpp",
    ],
    hdrs = [
        "ident.h",
        "//src/mongo/base:string_data.h",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_library(
    name = "record_store_test_harness",
    srcs = [
        "oplog_truncation_test.cpp",
        "record_store_test_datafor.cpp",
        "record_store_test_datasize.cpp",
        "record_store_test_deleterecord.cpp",
        "record_store_test_harness.cpp",
        "record_store_test_insertrecord.cpp",
        "record_store_test_oplog.cpp",
        "record_store_test_randomiter.cpp",
        "record_store_test_recorditer.cpp",
        "record_store_test_recordstore.cpp",
        "record_store_test_storagesize.cpp",
        "record_store_test_truncate.cpp",
        "record_store_test_updaterecord.cpp",
        "record_store_test_updatewithdamages.cpp",
    ],
    hdrs = [
        "record_store_test_harness.h",
        "test_harness_helper.h",
    ],
    deps = [
        ":oplog_truncation",
        ":record_store_base",
        ":storage_options",
        "//src/mongo/db:record_id_helpers",
        "//src/mongo/db:service_context",
        "//src/mongo/db:service_context_test_fixture",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/catalog:collection_options",
        "//src/mongo/db/catalog:health_log_interface",
        "//src/mongo/db/catalog:health_log_mock",
        "//src/mongo/db/update:update_document_diff",
        "//src/mongo/unittest",
    ],
)

mongo_cc_library(
    name = "recovery_unit_test_harness",
    srcs = [
        "recovery_unit_test_harness.cpp",
    ],
    hdrs = [
        "recovery_unit_test_harness.h",
        "test_harness_helper.h",
    ],
    deps = [
        ":record_store_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db:service_context_test_fixture",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/unittest",
    ],
)

mongo_cc_library(
    name = "sorted_data_interface_test_harness",
    srcs = [
        "sorted_data_interface_test_assert.h",
        "sorted_data_interface_test_harness.cpp",
        "test_harness_helper.h",
    ],
    hdrs = [
        "sorted_data_interface_test_harness.h",
    ],
    deps = [
        ":index_entry_comparison",
        ":storage_options",
        "//src/mongo/db:record_id_helpers",
        "//src/mongo/db:service_context",
        "//src/mongo/db:service_context_test_fixture",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/storage/key_string",
        "//src/mongo/unittest",
    ],
)

mongo_cc_library(
    name = "sorted_data_interface_tests",
    srcs = [
        "sorted_data_interface_test_bulkbuilder.cpp",
        "sorted_data_interface_test_cursor.cpp",
        "sorted_data_interface_test_cursor_advanceto.cpp",
        "sorted_data_interface_test_cursor_end_position.cpp",
        "sorted_data_interface_test_cursor_locate.cpp",
        "sorted_data_interface_test_cursor_saverestore.cpp",
        "sorted_data_interface_test_cursor_seek_exact.cpp",
        "sorted_data_interface_test_dupkeycheck.cpp",
        "sorted_data_interface_test_fullvalidate.cpp",
        "sorted_data_interface_test_insert.cpp",
        "sorted_data_interface_test_isempty.cpp",
        "sorted_data_interface_test_key_value_view.cpp",
        "sorted_data_interface_test_keyformat_string.cpp",
        "sorted_data_interface_test_rollback.cpp",
        "sorted_data_interface_test_spaceused.cpp",
        "sorted_data_interface_test_unindex.cpp",
    ],
    deps = [
        ":sorted_data_interface_test_harness",
        ":storage_options",
        "//src/mongo/db:shard_role_api",
    ],
)

mongo_cc_unit_test(
    name = "db_storage_test",
    srcs = [
        "collection_truncate_markers_test.cpp",
        "disk_space_monitor_test.cpp",
        "flow_control_test.cpp",
        "index_entry_comparison_test.cpp",
        "storage_engine_lock_file_test.cpp",
        "storage_engine_metadata_test.cpp",
        "storage_engine_test_fixture.h",
        "storage_repair_observer_test.cpp",
        "//src/mongo/db/storage/kv:durable_catalog_test.cpp",
        "//src/mongo/db/storage/kv:kv_drop_pending_ident_reaper_test.cpp",
        "//src/mongo/db/storage/kv:storage_engine_test.cpp",
    ],
    tags = ["mongo_unittest_first_group"],
    deps = [
        ":disk_space_monitor",
        ":flow_control",
        ":flow_control_parameters",
        ":record_store_base",
        ":storage_engine_common",
        ":storage_engine_lock_file",
        ":storage_engine_metadata",
        ":storage_options",
        "//src/mongo/db:dbhelpers",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db:shard_role",
        "//src/mongo/db:startup_recovery",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/catalog:catalog_impl",
        "//src/mongo/db/catalog:catalog_test_fixture",
        "//src/mongo/db/catalog:collection_options",
        "//src/mongo/db/concurrency:flow_control_ticketholder",
        "//src/mongo/db/index_builds:resumable_index_builds_idl",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/repl:topology_coordinator",
        "//src/mongo/db/storage:durable_catalog",
        "//src/mongo/db/storage:storage_control",
        "//src/mongo/db/storage:storage_engine_impl",
        "//src/mongo/db/storage:storage_repair_observer",
        "//src/mongo/db/storage/devnull:storage_devnull_core",
        "//src/mongo/db/storage/key_string",
        "//src/mongo/db/storage/kv:kv_drop_pending_ident_reaper",
        "//src/mongo/db/storage/wiredtiger:storage_wiredtiger",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/executor:network_interface_factory",
        "//src/mongo/executor:network_interface_mock",
        "//src/mongo/idl:server_parameter_test_util",
        "//src/mongo/util:periodic_runner_factory",
    ],
)

mongo_cc_library(
    name = "sorted_data_interface_test_assert",
    hdrs = [
        "sorted_data_interface_test_assert.h",
    ],
)

# TODO(SERVER-96857): Remove cycle created by moving //src/mongo/db/storage:record_store.h to //src/mongo/db/storage:record_store_base
filegroup(
    name = "record_store_hdrs",
    srcs = [":record_store.h"],
)

# TODO(SERVER-96857): Remove cycle created by moving //src/mongo/db/storage:recovery_unit.h to //src/mongo/db/storage:recovery_unit_base
filegroup(
    name = "recovery_unit_hdrs",
    srcs = [":recovery_unit.h"],
)

# TODO(SERVER-96857): Remove cycle created by moving //src/mongo/db/storage:write_unit_of_work.h to //src/mongo/db/storage:write_unit_of_work
filegroup(
    name = "write_unit_of_work_hdrs",
    srcs = [":write_unit_of_work.h"],
)
